#!/usr/bin/env python3
# -*- coding: utf-8 -*-
__author__ = 'sundx'

from collections import deque

# 定义节点信息
graph = {
    'you': ['alice', 'bob', 'claire'],
    'bob': ['anuj', 'peggy'],
    'alice': ['peggy'],
    'claire': ['tom', 'jonny'],
    'anuj': [],
    'peggy': [],
    'tom': [],
    'jonny': []
}

def personIsSeller(char):
    return char[-1] == 'm'

def breadSearch(name):
    # 创建一个双端队列
    search_queue = deque()
    search_queue += graph[name]
    # 创建一个搜索过的数组
    searched = []
    while search_queue:  # 队列内有元素时
        # 从队列中拿出最左边的元素
        person = search_queue.popleft()
        # 如果不在已搜索的数组内
        if person not in searched:
            if personIsSeller(person):
                print('found it, the name is ' + person)
                return True
            else:
                # 将该元素的节点加入队列
                search_queue += graph[person]
                # 更新为已搜索
                searched.append(person)
    return False

breadSearch('you')


